//
//  DTViewController.swift
//  UI
//
//  Created by admin on 14/9/18.
//  Copyright (c) 2014年 sinosun. All rights reserved.
//

import UIKit

class DTViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        var segment = UISegmentedControl(items: ["ripple","curl","uncurl","suck"])
        segment.selectedSegmentIndex = 0
        self.navigationItem.titleView = segment
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "go", style: UIBarButtonItemStyle.Bordered, target: self, action: "go")
        
    }
    
    
    func go(){
        var animation: CATransition = CATransition()
        animation.delegate = self
        animation.duration = 1.0
        
        switch (self.navigationItem.titleView as UISegmentedControl).selectedSegmentIndex{
        case 0:
            animation.type = "rippleEffect";
            break;
        case 1:
            animation.type = "pageCurl";
            break;
        case 2:
            animation.type = "pageUnCurl";
            break;
        case 3:
            animation.type = "suckEffect";
            break;
        default:
            break;
        }
        
        animation.subtype = kCATransitionFromRight;
        
        self.view.exchangeSubviewAtIndex(0, withSubviewAtIndex: 1)
        
        self.view.layer.addAnimation(animation, forKey: "000")
    
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
        
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
